{% extends "admin/base/base.html" %}
{% block title %}<title>广告管理</title>{% endblock %}
{% block page_navbar %}
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        内容管理
        <span class="c-gray en">&gt;</span>
        广告管理
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
{% endblock %}
{% block navbar %}
    {% include "admin/base/content_navbar.html" %}
{% endblock %}
{% block content %}
    <article class="cl pd-20" style="min-height: 51em">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
            <a href="javascript:void(0);"
               onclick="add('添加广告','{{ url_for("admin.ad_add") }}','','360')"
               class="btn btn-primary radius">
                <i class="Hui-iconfont">&#xe600;</i> 添加广告
            </a>
            </span>
            <span class="r">共有数据：<strong>{{ count }}</strong> 条</span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="40">ID</th>
                    <th width="400">标题</th>
                    <th width="60">缩略图</th>
                    <th>指向链接</th>
                    <th width="120">创建时间</th>
                    <th width="80">操作</th>
                </tr>
                </thead>
                <tbody>
                {% for vo in result %}
                    <tr class="text-c">
                        <td><input type="checkbox" value="{{ vo.id }}" name="id"></td>
                        <td>{{ vo.id }}</td>
                        <td style="text-align: left">{{ vo.name }}</td>
                        <td style="text-align: left">
                            <img class="picture-thumb" src="{{ url_for("static",filename="uploads/images/"+vo.image) }}"
                                 width="50">
                        </td>
                        <td style="text-align: left"><a href="{{ vo.path }}">{{ vo.path }}</a></td>
                        <td>{{ vo.create_time }}</td>
                        <td style="font-size: 16px">
                            {% if vo.status == 1 %}
                                <a style="text-decoration:none;"
                                   onClick="start_or_stop('{{ url_for("admin.ad_stop",id=vo.id) }}')"
                                   href="javascript:void(0);" title="停用"><i
                                        class="Hui-iconfont c-green">&#xe631;</i></a>
                            {% else %}
                                <a style="text-decoration:none"
                                   onClick="start_or_stop('{{ url_for("admin.ad_start",id=vo.id) }}')"
                                   href="javascript:void(0);" title="启用"><i class="Hui-iconfont c-red">&#xe601;</i></a>
                            {% endif %}
                            <a title="编辑" href="javascript:void(0);"
                               onclick="edit('编辑广告','{{ url_for('admin.ad_edit',id=vo.id) }}','','360')"
                               class="ml-5" style="text-decoration:none">
                                <i class="Hui-iconfont c-orange">&#xe6df;</i>
                            </a>
                            <a title="删除" href="javascript:void(0);"
                               onclick="del(this,'{{ url_for('admin.ad_del',id=vo.id) }}')"
                               class="ml-5" style="text-decoration:none">
                                <i class="Hui-iconfont c-red">&#xe6e2;</i>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </article>
{% endblock %}
{% block js %}
    <script type="text/javascript"
            src="{{ url_for("static",filename="admin/lib/My97DatePicker/4.8/WdatePicker.js") }}"></script>
    <script type="text/javascript"
            src="{{ url_for("static",filename="admin/lib/datatables/1.10.0/jquery.dataTables.min.js") }}"></script>
    <script type="text/javascript" src="{{ url_for("static",filename="admin/lib/laypage/1.2/laypage.js") }}"></script>
    <script type="text/javascript">
        $('.table-sort').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable": false, "aTargets": [0, 4]}// 制定列不参与排序
            ]
        });
        $(document).ready(function () {
            $("#menu-ad dt").addClass("selected");
            $("#menu-ad dd").css("display", "block");
            $("#menu-ad #ad").addClass("current");
            $("#content").addClass("current")
        });

        function add(title, url, w, h) {
            layer_show(title, url, w, h)
        }

        function edit(title, url, w, h) {
            layer_show(title, url, w, h)
        }

        function del(obj, url) {
            $.ajax({
                type: 'POST',
                url: url,
                dataType: 'json',
                success: function (result) {
                    if (result.status === 1) {
                        $(obj).parents("tr").remove();
                        layer.msg(result.data, {icon: 1, time: 1000});
                    } else {
                        layer.msg(result.data, {icon: 5, time: 1000});
                    }
                }
            });
        }

        function start_or_stop(url) {
            $.ajax({
                type: "POST",
                url: url,
                dataType: "json",
                success: function (result) {
                    if (result.status === 1) {
                        layer.msg(result.data, {icon: 1, time: 1000});
                        window.parent.location.replace(location.href);
                    } else {
                        layer.msg(result.data, {icon: 5, time: 1000})
                    }
                }
            })
        }
    </script>
{% endblock %}